#ifndef _CANARY2_UTIL_SCHEDULE_BIND_H_
#define _CANARY2_UTIL_SCHEDULE_BIND_H_

#include <functional>
#include "../sys/scheduler_concepts.h"
#include "../coro/task.h"

namespace wilson::util
{
    template<typename Schr, coro::as_task Task>
    requires (sys::scheduler<Schr> || sys::task_manager<Schr>)
    ::std::function<void()> 
    schedule_bind(Schr& schr, Task task)
    {
        return [&schr, tp = ::std::make_shared<Task>(::std::move(task))] mutable {
            schedule(schr, sys::resumable(::std::move(*tp)));
        };
    }

    template<typename Schr>
    requires (sys::scheduler<Schr> || sys::task_manager<Schr>)
    ::std::function<void()> 
    schedule_bind(Schr& schr, ::std::coroutine_handle<> h)
    {
        auto rp = ::std::make_shared<sys::resumable>(h);
        return [&schr, rp = ::std::move(rp)] {
            schedule(schr, ::std::move(*rp));
        };
    }
}

#endif
